package Panel;
import DAO.LoaiNhanVienDAO;
import DAO.NhanVienDAO;
import OBJECT.LoaiNhanVien;
import OBJECT.NhanVien;
import java.awt.event.ItemEvent;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QuanLyNhanVien.java
 *
 * Created on Oct 10, 2012, 10:04:41 AM
 */


/**
 *
 * @author TAN
 */
public class QuanLyNhanVien extends javax.swing.JPanel {
     NhanVienDAO nvdao;
     LoaiNhanVienDAO lnvdao;
    DefaultTableModel tablemodel;
   //DefaultComboBoxModel comboboxmodel=new DefaultComboBoxModel();
    /** Creates new form QuanLyNhanVien */
    public QuanLyNhanVien(String User ,String Pass,String port,String DataBase,String Host) {
        initComponents();
         tbdanhsach.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          tablemodel = new DefaultTableModel();
        tablemodel.addColumn("Mã NV");
        tablemodel.addColumn("Tên NV");
        tablemodel.addColumn("Địa Chỉ");
        tablemodel.addColumn("Điện Thoại");
        tablemodel.addColumn("Tình Trạng");
        tbdanhsach.setModel(tablemodel);
        tbdanhsach.setEnabled(true);
        lnvdao=new LoaiNhanVienDAO(User , Pass, port, DataBase, Host);
        nvdao =new NhanVienDAO(User , Pass, port, DataBase, Host);
        cbLoaiNhanVien.removeAllItems();
        ArrayList<LoaiNhanVien> dsloainv=lnvdao.DanhSachLoaiNhanVien()   ; 
        for(int i=0;i<dsloainv.size();i++)
        {
            cbLoaiNhanVien.addItem(dsloainv.get(i));
           
        }
      showList();
               
       
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtTen = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDiaChi = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        txtDienThoai = new javax.swing.JTextField();
        txtLuong = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtUserName = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPassWord = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtMaNV = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtTinhTrang = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cbLoaiNhanVien = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        cbThaoTac = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbdanhsach = new javax.swing.JTable();
        lbsoluong = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông Tin Nhân Viên"));

        jLabel1.setText("Tên");

        jLabel2.setText("Địa Chỉ");

        txtDiaChi.setColumns(20);
        txtDiaChi.setRows(5);
        jScrollPane1.setViewportView(txtDiaChi);

        jLabel3.setText("Điện Thoại");

        txtDienThoai.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDienThoaiFocusLost(evt);
            }
        });

        txtLuong.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtLuongFocusLost(evt);
            }
        });

        jLabel4.setText("Lương");

        jLabel5.setText("Username");

        jLabel6.setText("PassWord");

        jLabel7.setText("Mã NV");

        jLabel9.setText("Tình Trạng");

        jLabel10.setText("Loại NV");

        cbLoaiNhanVien.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(38, 38, 38)
                        .addComponent(txtMaNV, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtPassWord, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                    .addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                    .addComponent(txtLuong, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                    .addComponent(txtDienThoai, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtTen, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbLoaiNhanVien, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtTinhTrang, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)))))
                    .addComponent(jLabel10))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtMaNV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(74, 74, 74)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(txtPassWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(cbLoaiNhanVien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thao Tác"));

        cbThaoTac.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Insert", "Update", "Delete", " " }));
        cbThaoTac.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbThaoTacItemStateChanged(evt);
            }
        });

        jButton1.setText("Apply");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbThaoTac, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(cbThaoTac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh Sách Nhân Viên"));

        tbdanhsach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbdanhsach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbdanhsachMousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(tbdanhsach);

        lbsoluong.setText("Số Lượng");

        jLabel8.setText("Nhân Viên");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(lbsoluong)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbsoluong)
                    .addComponent(jLabel8))
                .addGap(29, 29, 29)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cbThaoTacItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbThaoTacItemStateChanged
        // TODO add your handling code here:
         if(evt.getStateChange() == ItemEvent.SELECTED){
            String option = this.cbThaoTac.getSelectedItem().toString();
            Clear();
            if(option.equals("Insert")){
                this.txtTen.setEditable(true);
                this.txtDiaChi.setEditable(true);
                this.txtDienThoai.setEditable(true);
               this.txtUserName.setEditable(true);
               this.txtPassWord.setEditable(true);
               this.txtMaNV.setEditable(false);
               this.txtTinhTrang.setEditable(false);
                //this.tbdanhsach.setEnabled(false);
                this.txtLuong.setEditable(true);
               this.tbdanhsach.clearSelection();
              
               
            }else if(option.equals("Delete")){
                 this.txtTen.setEditable(false);
                this.txtDiaChi.setEditable(false);
                this.txtDienThoai.setEditable(false);
               this.txtUserName.setEditable(false);
               this.txtPassWord.setEditable(false);
               this.txtMaNV.setEditable(true);
               this.txtTinhTrang.setEditable(false);
               this.txtLuong.setEditable(false);
                this.tbdanhsach.setEnabled(true);
                
            }
            else if(option.equals("Update"))
            {
                  this.txtTen.setEditable(true);
                this.txtDiaChi.setEditable(true);
                this.txtDienThoai.setEditable(true);
               this.txtUserName.setEditable(true);
               this.txtPassWord.setEditable(true);
               this.txtTinhTrang.setEditable(true);
               this.txtMaNV.setEditable(true);
               this.txtLuong.setEditable(true);
               this.tbdanhsach.setEnabled(true);
                    
            }
        }
    }//GEN-LAST:event_cbThaoTacItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:\
         String option = cbThaoTac.getSelectedItem().toString();
         if(option.equals("Insert"))
         {
             NhanVien nv= new NhanVien();
             nv.setDiaChi(txtDiaChi.getText());
             nv.setDienThoai(txtDienThoai.getText());
            // nv.setLoaiNhanVien(((LoaiNhanVien)comboboxmodel.getElementAt(cbLoaiNhanVien.getSelectedIndex())).getLoaiNhanVien());
            nv.setLoaiNhanVien(((LoaiNhanVien)cbLoaiNhanVien.getSelectedItem()).getLoaiNhanVien());
            
             nv.setLuong(Float.parseFloat(txtLuong.getText()));
             nv.setUserName(txtUserName.getText());
             nv.setPassWord(txtPassWord.getText());
             nv.setTen(txtTen.getText());
            String kt= nvdao.ThemNhanVien(nv);
            
                JOptionPane.showMessageDialog(this, kt,"OK",JOptionPane.INFORMATION_MESSAGE);
            clearList();
            showList();
            
            
         }
         else if(option.equals("Update"))
         {
             if(txtMaNV.getText().equals("")){
            JOptionPane.showMessageDialog(this, "Không Thể Bỏ Trống Mã Nhân Viên","Error",JOptionPane.ERROR_MESSAGE);
            return;
        }
             NhanVien nv= new NhanVien();
             nv.setManv(Integer.parseInt(txtMaNV.getText()));
             nv.setDiaChi(txtDiaChi.getText());
             nv.setDienThoai(txtDienThoai.getText());
            // nv.setLoaiNhanVien(((LoaiNhanVien)comboboxmodel.getElementAt(cbLoaiNhanVien.getSelectedIndex())).getLoaiNhanVien());
            nv.setLoaiNhanVien(((LoaiNhanVien)cbLoaiNhanVien.getSelectedItem()).getLoaiNhanVien());
            
             nv.setLuong(Float.parseFloat(txtLuong.getText()));
             nv.setUserName(txtUserName.getText());
             nv.setPassWord(txtPassWord.getText());
             nv.setTen(txtTen.getText());
             nv.setTinhTrang(txtTinhTrang.getText());
            boolean kt= nvdao.SuaNhanVien(nv);
            if(kt==true)
            {
                JOptionPane.showMessageDialog(this, "Successfull","OK",JOptionPane.INFORMATION_MESSAGE);
            clearList();
            showList();
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Fail","Error",JOptionPane.ERROR_MESSAGE);
            }
         }
         else if(option.equals("Delete"))
         {
             if(txtMaNV.getText().equals(""))
             {
                 JOptionPane.showMessageDialog(null, "Nhập Mã Nhân Viên Cần Xóa", "Error", JOptionPane.ERROR_MESSAGE);
                return;
             }
             int inform = JOptionPane.showConfirmDialog(null, "Bạn Có Muốn Xóa Hay Không ???");
             if(inform == JOptionPane.OK_OPTION){
           String kt= nvdao.XoaNhanVien(Integer.parseInt(txtMaNV.getText()));
            
            
                JOptionPane.showMessageDialog(this, kt,"OK",JOptionPane.INFORMATION_MESSAGE);
            clearList();
            showList();
            
             
             }
         }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtLuongFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtLuongFocusLost
        // TODO add your handling code here:
          try{
            if(!this.txtLuong.getText().equals("")){
             float temp = Float.parseFloat(this.txtLuong.getText());
            }
            else{
                this.txtLuong.setText("5000000");
            }
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null, "Lỗi NumberFormat");
            this.txtLuong.setText("");
            this.txtLuong.requestFocus();
        }
    }//GEN-LAST:event_txtLuongFocusLost

    private void txtDienThoaiFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDienThoaiFocusLost
        // TODO add your handling code here:
          try{
            if(!this.txtDienThoai.getText().equals("")){
             Float temp = Float.parseFloat(this.txtDienThoai.getText());
            }
            else{
                this.txtDienThoai.setText("01207800532");
            }
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null, "Điện thoại Phải Là Số");
            this.txtDienThoai.setText("");
            this.txtDienThoai.requestFocus();
        }
    }//GEN-LAST:event_txtDienThoaiFocusLost

    private void tbdanhsachMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbdanhsachMousePressed
        // TODO add your handling code here:
        
        String option = this.cbThaoTac.getSelectedItem().toString();
     if(option.equals("Insert"))
     {
         JOptionPane.showMessageDialog(this, "tabel không thể thao tác khi ở chế độ insert","Error",JOptionPane.ERROR_MESSAGE); 
         return;
     }
     else
     {
         NhanVien nv ;
    int row = this.tbdanhsach.getSelectedRow();
   
    nv = nvdao.Search1NhanVien(Integer.parseInt(tbdanhsach.getValueAt(row, 0).toString()));
    if(nv!=null)
    {
       
    txtDiaChi.setText(nv.getDiaChi());
    txtDienThoai.setText(nv.getDienThoai());
    txtLuong.setText(""+nv.getLuong());
    txtMaNV.setText(""+nv.getManv());
    txtPassWord.setText(nv.getPassWord());
    txtTen.setText(nv.getTen());
    txtTinhTrang.setText(nv.getTinhTrang());
    txtUserName.setText(nv.getUserName());
     
    for(int i=0;i<cbLoaiNhanVien.getItemCount();i++)
    {
        if(((LoaiNhanVien)cbLoaiNhanVien.getItemAt(i)).getLoaiNhanVien()==nv.getLoaiNhanVien())
        {
            cbLoaiNhanVien.setSelectedIndex(i);
            break;
        }
    }
    }
    else
    {
        ;
    }
     }
    }//GEN-LAST:event_tbdanhsachMousePressed
private void showList()
{
                    String Soluong="";
                   CallableStatement cls=nvdao.DanhSachNhanVien();
                   try
                   {
                   cls.registerOutParameter(1, java.sql.Types.INTEGER);
                   
                   cls.execute();
                    
                     
                    
                      ResultSet result=cls.getResultSet();   
                      
                      
                   while(result.next())
                    {
                            Vector vt = new Vector();
                            vt.add(result.getInt("Ma_NV"));
                            vt.add(result.getString("Ten_NV"));
                            vt.add(result.getString("DiaChi"));
                            vt.add(result.getString("DienThoai"));
                            vt.add(result.getString("TinhTrang"));
                            tablemodel.addRow(vt);
                    }
                   result.close();
                       Soluong=""+cls.getInt(1);    
                    cls.close();
                    nvdao.CloseConnect();
                   }catch(Exception e)
                   {
                      ;
                   }
                
                   lbsoluong.setText(Soluong);
                   
                           
//                    ArrayList<NhanVien> list = nvdao.DanhSachNhanVien();
//                    for(int i = 0 ; i < list.size() ; i++)
//                    {
//                        Vector vt = new Vector();
//                        vt.add(list.get(i).getManv());
//                        vt.add(list.get(i).getTen());
//                        vt.add(list.get(i).getDiaChi());
//                        vt.add(list.get(i).getDienThoai());
//                        vt.add(list.get(i).getTinhTrang());
//                        tablemodel.addRow(vt);
//                     }
//                    
}
private void clearList()
{
   for(int i = tablemodel.getRowCount() -1;i >= 0;i--)
            tablemodel.removeRow(i);
   
}
private void Clear(){
        txtDiaChi.setText("");
        txtDienThoai.setText("");
        txtLuong.setText("");
        txtMaNV.setText("");
        txtPassWord.setText("");
        txtTen.setText("");
        txtTinhTrang.setText("");
        txtUserName.setText("");
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbLoaiNhanVien;
    private javax.swing.JComboBox cbThaoTac;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbsoluong;
    private javax.swing.JTable tbdanhsach;
    private javax.swing.JTextArea txtDiaChi;
    private javax.swing.JTextField txtDienThoai;
    private javax.swing.JTextField txtLuong;
    private javax.swing.JTextField txtMaNV;
    private javax.swing.JTextField txtPassWord;
    private javax.swing.JTextField txtTen;
    private javax.swing.JTextField txtTinhTrang;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
}
